package com.haogu.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.haogu.entity.Record;
import com.haogu.entity.User;
import com.haogu.mapper.RecordMapper;
import com.haogu.util.SendMessageUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/pub")
public class PubController {
    @Resource
    private RecordMapper recordMapper;
    @RequestMapping("/duanxin")
    @ResponseBody
    public Map duanXin(String sendtoname, String phone, String content, HttpSession session){
        User user = (User)session.getAttribute("user");
        Integer send = SendMessageUtil.send("54sjs", "d41d8cd98f00b204e980", phone, content);
        System.out.println(SendMessageUtil.getMessage(send));
        Map map = new HashMap();
        if(send>0){

            Record record = new Record(user.getId(),phone,content,new Date(),sendtoname);
            recordMapper.insert(record);
            map.put("success",true);
            map.put("message","信息发送成功");
        }else{
            map.put("success",false);
            map.put("message","信息发送失败");
        }
        return map;
    }

}
